package sdc.media.motorbike.Controller;

import sdc.media.motorbike.Model.UserData;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.Manifold;

public class MyContactListener implements ContactListener {

	public boolean isGameOver = false;
	
	@Override
	public void beginContact(Contact contact) {
		// TODO Auto-generated method stub
		Fixture fixtureA = contact.getFixtureA();
		Fixture fixtureB = contact.getFixtureB();
		
		if(fixtureA.getBody().getUserData() instanceof UserData &&
		   fixtureB.getBody().getUserData() instanceof UserData) {
			UserData data1 = (UserData) fixtureA.getBody().getUserData();
			UserData data2 = (UserData) fixtureB.getBody().getUserData();
				System.out.println("Va cham");
				Gdx.app.log("User data", ""+data1.getName()+", "+data2.getName());
				if((data1.getName() == "Motor_Bike" && data2.getName() == "Car") ||
				   (data2.getName() == "Motor_Bike" && data1.getName() == "Car") ||
				   (data1.getName() == "Motor_Bike" && data2.getName() == "Street_Left") ||
				   (data2.getName() == "Motor_Bike" && data1.getName() == "Street_Left") ||
				   (data1.getName() == "Motor_Bike" && data2.getName() == "Street_Right") ||
				   (data2.getName() == "Motor_Bike" && data1.getName() == "Street_Right") ||
				   (data1.getName() == "Motor_Bike" && data2.getName() == "World_Box") ||
				   (data2.getName() == "Motor_Bike" && data1.getName() == "World_Box"))
						isGameOver = true;
				
		}
	}

	@Override
	public void endContact(Contact contact) {
		// TODO Auto-generated method stub
		Fixture fixtureA = contact.getFixtureA();
		Fixture fixtureB = contact.getFixtureB();
		if(fixtureA.getBody().getUserData() instanceof UserData &&
		   fixtureB.getBody().getUserData() instanceof UserData) {	
				System.out.println("Ket thuc va cham");	
		}
	}

	@Override
	public void preSolve(Contact contact, Manifold oldManifold) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postSolve(Contact contact, ContactImpulse impulse) {
		// TODO Auto-generated method stub
		
	}
	
}
